A quick illustration of using SLaTeX

Other packages [7] for typesetting code fragments use a verbatim environment that uses a monospace typewriter font. This monospace ensures that the indentation is not affected. However, the resulting output fails to distinguish between the various tokens used in the code, e.g., boldface for keywords like define and lambda, sans-serif for constants like #t and 42, and italics for variables such as x and y in (lambda (x y) (cons x (cons y '()))). enableslatex

The program SLaTeX provides a convenient way of capturing the indentation information as well as assigning distinguishing fonts to code tokens without requiring the user to do worry about fonting and spacing. It uses temporary files to store its TeXset version of the user's code and then calls LaTeX on the user's LaTeX files as well as these temporaries.

For a quick tutorial on the basic SLaTeX control sequences, their use, and the running of the SLaTeX program, consider the following LaTeX (and SLaTeX) file, quick.tex:

% quick.tex
\documentstyle[11pt,slatex]{article}
\begin{document}

In Scheme, the expression \scheme|(set! x 42)| returns an
unspecified value, rather than \scheme'42'.  However, one
could get a \scheme{set!} of the latter style by:

\begin{schemedisplay}
(extend-syntax (setq)
  [(setq x a)
   (begin (set! x a)
	  x)])
\end{schemedisplay}

\end{document}

Thus, in-text code is introduced by the SLaTeX control sequence \scheme and is flanked by a pair of identical characters that are not alphabets or {. As a special convenient case, SLaTeX also allows the form \scheme{...}. The SLaTeX control sequences (``environment'') for displayed code are the opening \begin{schemedisplay} and the closing \end{schemedisplay}. One of the \documentstyles is slatex. (You could also have written ``\input slatex.sty'' in your file, where the file called slatex.sty (supplied with SLaTeX) contains these and other SLaTeX-specific control sequences.)

The file is now SLaTeX'd by running command slatex (say, from the Un*x command line) on it:


slatex quick   (or slatex quick.tex)

This calls a Scheme program that TeXsets the code fragments identified by the commands \scheme and \begin/\end{schemedisplay}, and then calls LaTeX on the result. The final result is the quick.dvi file, which when viewed or printed, looks like:

In Scheme, the expression |(set! x 42)| returns an unspecified value, rather than '42'. However, one could get a set! of the latter style by:


\begin{schemedisplay}
(extend-syntax (setq)
[(setq x a)
(begin (set! x a)
x)])
\end{schemedisplay}
enableslatex